<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="jakarta.tags.core" %>
<%@ taglib prefix="fmt" uri="jakarta.tags.fmt" %>
<html>
<head>
    <title>订单详情 - 万万书城</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 0;
            background-color: #f5f5f5;
        }
        .header {
            background-color: #4CAF50;
            color: white;
            padding: 15px 0;
            box-shadow: 0 2px 4px rgba(0,0,0,0.1);
        }
        .header-container {
            max-width: 1200px;
            margin: 0 auto;
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 0 20px;
        }
        .logo {
            font-size: 24px;
            font-weight: bold;
        }
        .nav a {
            color: white;
            text-decoration: none;
            margin: 0 15px;
        }
        .nav a:hover {
            text-decoration: underline;
        }
        .content {
            max-width: 1200px;
            margin: 20px auto;
            padding: 0 20px;
        }
        .detail-container {
            background-color: white;
            border-radius: 8px;
            box-shadow: 0 2px 4px rgba(0,0,0,0.1);
            padding: 20px;
        }
        h2 {
            margin-top: 0;
            color: #333;
        }
        .section {
            margin-bottom: 30px;
            padding: 20px;
            border: 1px solid #ddd;
            border-radius: 8px;
        }
        .section h3 {
            margin-top: 0;
            color: #555;
            border-bottom: 1px solid #eee;
            padding-bottom: 10px;
        }
        .info-item {
            margin-bottom: 10px;
            display: flex;
        }
        .info-label {
            width: 100px;
            color: #666;
        }
        .info-value {
            flex: 1;
        }
        .status-badge {
            padding: 5px 15px;
            background-color: #4CAF50;
            color: white;
            border-radius: 20px;
            font-size: 16px;
            display: inline-block;
        }
        .order-table {
            width: 100%;
            border-collapse: collapse;
        }
        .order-table th, .order-table td {
            padding: 12px;
            text-align: left;
            border-bottom: 1px solid #ddd;
        }
        .order-table th {
            background-color: #f0f0f0;
        }
        .total-price {
            font-size: 20px;
            font-weight: bold;
            color: #e74c3c;
        }
        .btn {
            padding: 10px 20px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-size: 16px;
            text-decoration: none;
        }
        .btn-primary {
            background-color: #4CAF50;
            color: white;
        }
        .btn-primary:hover {
            background-color: #45a049;
        }
        .user-info {
            color: white;
        }
        .user-info a {
            color: white;
            margin-left: 10px;
        }
    </style>
</head>
<body>
    <div class="header">
        <div class="header-container">
            <div class="logo">万万书城</div>
            <div class="nav">
                <a href="index.jsp">首页</a>
                <a href="cart">购物车</a>
                <a href="order?action=list">我的订单</a>
                <a href="userCenter">用户中心</a>
            </div>
            <div class="user-info">
                <% if (session.getAttribute("user") != null) {
                    com.wanwanbookstore.entity.User user = (com.wanwanbookstore.entity.User) session.getAttribute("user");
                    out.println(user.getUsername() + " <a href='logout'>退出</a>");
                } else {
                    out.println("<a href='login.jsp'>登录</a> <a href='register.jsp'>注册</a>");
                }
                %>
            </div>
        </div>
    </div>

    <div class="content">
        <div class="detail-container">
            <h2>订单详情</h2>
            
            <c:if test="${empty order}">
                <div style="text-align: center; padding: 50px; color: #666;">
                    <p>订单不存在</p>
                    <a href="order?action=list" class="btn btn-primary">返回订单列表</a>
                </div>
            </c:if>

            <c:if test="${not empty order}">
                <div class="section">
                    <h3>订单信息</h3>
                    <div class="info-item">
                        <div class="info-label">订单号：</div>
                        <div class="info-value">${order.id}</div>
                    </div>
                    <div class="info-item">
                        <div class="info-label">下单时间：</div>
                        <div class="info-value"><fmt:formatDate value="${order.createTime}" pattern="yyyy-MM-dd HH:mm:ss" /></div>
                    </div>
                    <div class="info-item">
                        <div class="info-label">订单状态：</div>
                        <div class="info-value">
                            <span class="status-badge">${order.status}</span>
                        </div>
                    </div>
                </div>

                <div class="section">
                    <h3>收货信息</h3>
                    <div class="info-item">
                        <div class="info-label">联系电话：</div>
                        <div class="info-value">${order.phone}</div>
                    </div>
                    <div class="info-item">
                        <div class="info-label">收货地址：</div>
                        <div class="info-value">${order.address}</div>
                    </div>
                </div>

                <div class="section">
                    <h3>商品信息</h3>
                    <table class="order-table">
                        <tr>
                            <th>商品</th>
                            <th>单价</th>
                            <th>数量</th>
                            <th>小计</th>
                        </tr>
                        <c:forEach items="${order.orderItems}" var="item">
                            <tr>
                                <td>${item.book.title}</td>
                                <td>¥${item.price}</td>
                                <td>${item.quantity}</td>
                                <td>¥${item.totalPrice}</td>
                            </tr>
                        </c:forEach>
                    </table>
                </div>

                <div class="section">
                    <h3>订单金额</h3>
                    <div style="text-align: right;">
                        <span class="total-price">总计：¥${order.totalPrice}</span>
                    </div>
                </div>

                <div style="text-align: center; margin-top: 20px;">
                    <a href="order?action=list" class="btn btn-primary">返回订单列表</a>
                </div>
            </c:if>
        </div>
    </div>
</body>
</html>